﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using BusinessLayer.RegInfo.Entities;
using BusinessLayer.RegInfo.Models;
using DBHelper;

namespace BusinessLayer.RegInfo
{
    public class LoginLogBL
    {
        public void Insert(LoginLog loginLog)
        {
            var adapter = new BaseDAO(DbConfig.DbRegInfoConnectionString);
            adapter.AddParameter("@Email", loginLog.Email);
            adapter.AddParameter("@PassWord", loginLog.PassWord);
            adapter.AddParameter("@Ip", loginLog.Ip);
            adapter.AddParameter("@Status", loginLog.Status);
            adapter.ExecuteNonQuery("sp_LoginLog_Insert", CommandType.StoredProcedure, CustomConnectionState.CloseOnExit);            
        }

        public List<LoginLogExtend> Search(string email, DateTime? fromDate, DateTime? toDate, int? status, int pageIndex, int pageSize, out int totalRecord)
        {
            var adapter = new BaseDAO(DbConfig.DbRegInfoConnectionString);
            adapter.AddParameter("@Email", email);
            adapter.AddParameter("@Status", status);
            adapter.AddParameter("@FromDate", fromDate);
            adapter.AddParameter("@ToDate", toDate);
            adapter.AddParameter("@PageIndex", pageIndex);
            adapter.AddParameter("@PageSize", pageSize);
            var output = adapter.AddParameter("@TotalRecord", SqlDbType.Int, ParameterDirection.Output);
            var list = adapter.GetList<LoginLogExtend>("sp_LoginLog_Search", CommandType.StoredProcedure, CustomConnectionState.CloseOnExit);
            totalRecord = Convert.ToInt32(output.Value);
            return list;
        } 
    }
}
